package com.welsy.usermgt.command
{
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.model.ModelLocator;
	import com.adobe.cairngorm.control.CairngormEvent;
	import flash.events.Event;
	import com.welsy.usermgt.business.SearchDelegate;
	import com.welsy.usermgt.event.SearchEvent;
	import com.welsy.usermgt.model.UserMgtModelLocator;
	import mx.controls.Alert;
	import com.welsy.usermgt.vo.SearchVO;
	import com.welsy.usermgt.vo.UsrResultVO;
	import mx.collections.ArrayCollection;
	import com.welsy.usermgt.vo.UserVO;
	import mx.rpc.IResponder;
	import com.welsy.usermgt.event.UpdateClassEvent;
	import com.welsy.usermgt.business.UpdateClassDelegate;
	import com.welsy.usermgt.vo.ClassVO;
	import com.welsy.usermgt.event.RemoveFromClassEvent;
	import com.welsy.usermgt.business.RemoveFromClassDelegate;
	import com.welsy.classroom.model.ClassModelLocator;
	
	public class RemoveFromClassCommand implements Command, IResponder
	{
		private var model : UserMgtModelLocator = UserMgtModelLocator.getInstance();
		
		public function execute(event : CairngormEvent):void {
			var delegate : RemoveFromClassDelegate = new RemoveFromClassDelegate(this);
			var removeFromClassEvent : RemoveFromClassEvent = RemoveFromClassEvent(event);
			delegate.removeUsers(removeFromClassEvent.classId,removeFromClassEvent.users);
		}
		
		public function result( event : Object) : void {
			var resultlist:XMLList = XMLList(event.result)
			var result:String = XML(resultlist.child(0).child(0)).toString()
			if(result.toLowerCase() == "ok") {
				UserMgtModelLocator.getInstance().classEditingSucceeded = true;
				ClassModelLocator.getInstance().classEditingSucceeded = true;
			} else {
				UserMgtModelLocator.getInstance().classEditingSucceeded = false;
				ClassModelLocator.getInstance().classEditingSucceeded = false;
				trace(result);
			}
		}
		
		public function fault( event : Object ) : void {
			UserMgtModelLocator.getInstance().classEditingSucceeded = false;
			//report the error
			Alert.show("usermgt.command.RemoveFromClassCommand.onFault!");
		}
	}
}